package com.huixuebao.settle.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huixuebao.settle.dto.UserDTO;
import com.huixuebao.settle.entity.UserEntity;
import com.huixuebao.settle.mapper.UserMapper;
import com.huixuebao.settle.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;
    /**
     * 根据手机号查询用户是否投保
     * @param phone
     * @return com.huixuebao.settle.dto.UserDTO
     * @date 2020-11-11 22:32
     */
    @Override
    public UserDTO getUserByPhone(String phone) {
        List<UserEntity> list = userMapper.selectList(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getPhone, phone));
        UserDTO userDTO = new UserDTO();
        if (CollUtil.isNotEmpty(list)) {
            BeanUtil.copyProperties(list.get(0), userDTO);
        }
        return userDTO;
    }
}
